import Vue from 'vue';

import VueRouter from 'vue-router';

import HomeView from '../views/Home.vue';

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location) {
  return originalPush.call(this, location).catch((err) => {});
};

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    name: "home",
    component: HomeView,
  },
  {
    path: "/goods",
    name: "goods",
    component: () => import("@/views/Goods.vue"),
  },
  {
    path: "/user",
    name: "user",
    redirect: "/user/profiles",
    component: () => import("@/views/User.vue"),
    children: [
      {
        path: "cart",
        component: () => import("@/components/user/Cart.vue"),
      },
      {
        path: "profiles",
        component: () => import("@/components/user/Profiles.vue"),
      },
    ],
  },
  {
    path: "/order",
    name: "order",
    component: () => import("@/views/Order.vue"),
  },
  {
    path: "/free",
    name: "free",
    component: () => import("@/views/Free.vue"),
  },
  {
    path: "/detail",
    name: "detail",
    component: () => import("@/views/Detail.vue"),
  },
  {
    path: "*",
    name: "Error",
    component: () => import("@/views/Error.vue"),
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

export default router;
